package clone.foundation;

/**
 * 不克隆时
 */

public class Test1 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Student student1 = new Student(1,23);
        Student student2 = student1.clone();
        System.out.println(student1.toString() + student2.toString());
        // 修改 student2 的值，student1 不会跟着变
        student2.setAge(88);
        System.out.println(student1.toString() + student2.toString());
    }
}
class Student implements Cloneable{
    public int ID;
    public int age;
    public int getID() {
        return ID;
    }
    public void setID(int iD) {
        ID = iD;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }


    public Student(int iD, int age) {
        super();
        ID = iD;
        this.age = age;
    }
    @Override
    public String toString() {
        return "Student [ID=" + ID + ", age=" + age + "]";
    }

    @Override
    public Student clone() throws CloneNotSupportedException {
        return (Student) super.clone();
    }

}
